package com.hnkywl.sts.util;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-7-3
 * Time: 下午4:20
 * To change this template use File | Settings | File Templates.
 */
public class ProxyServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {


        String username = request.getParameter("username");
        username=java.net.URLEncoder.encode(username,"utf-8");
        String url = "http://218.22.80.106:1389/bbs/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1&fastloginfield=username&username=" + username + "&password=111111&quickforward=yes&handlekey=ls";
        String curLine;
        String content = StringUtils.EMPTY;
        URL server = new URL(url);
        HttpURLConnection connection = (HttpURLConnection) server.openConnection();
        connection.connect();
        InputStream is = connection.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        while ((curLine = reader.readLine()) != null) {
            content = content + curLine + "";
        }
        is.close();
        response.setContentType("text/xml;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.print(content);
    }
}
